package com.xian.d5_collection_list;

import java.util.ArrayList;
import java.util.Iterator;

public class ListDemo2 {
    public static void main(String[] args) {
        ArrayList<String> lists = new ArrayList<>();
        lists.add("java1");
        lists.add("java2");
        lists.add("java3");

        /**(1) for循环 */
        System.out.println("-------------------------------------");
        for (int i = 0; i < lists.size(); i++) {
            String ele = lists.get(i);
            System.out.println(ele);
        }
        /**(2) 迭代器 */
        System.out.println("-------------------------------------");
        Iterator<String> it = lists.iterator();
        while (it.hasNext()) {
            String ele = it.next();
            System.out.println(ele);
        }

        /**(3) foreach */
        System.out.println("-------------------------------------");
        for (String list : lists) {
            System.out.println(list);
        }

        /**(4) JDK 1.8开始之后的Lambda表达式 */
        System.out.println("-------------------------------------");
        lists.forEach(s -> System.out.println(s));

    }
}
